<!DOCTYPE html>
<html lang="en">

<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
	<meta name="keywords" content="Seata" />
	<meta name="description" content="Seata分TC、TM和RM三个角色，TC（Server端）为单独服务端部署，TM和RM（Client端）由业务系统集成。" />
	<!-- 网页标签标题 -->
	<title>Seata部署指南</title>
  <link rel="shortcut icon" href="/img/seata_logo_small.jpeg"/>
	<link rel="stylesheet" href="/build/documentation.css" />
</head>
<body>
	<div id="root"><div class="documentation-page" data-reactroot=""><header class="header-container header-container-normal"><div class="header-body"><a href="/zh-cn/index.html"><img class="logo" src="/img/seata_logo.png"/></a><div class="search search-normal"><span class="icon-search"></span></div><span class="language-switch language-switch-normal">En</span><div class="header-menu"><img class="header-menu-toggle" src="/img/system/menu_gray.png"/><ul><li class="menu-item menu-item-normal"><a href="/zh-cn/index.html" target="_self">首页</a></li><li class="menu-item menu-item-normal menu-item-normal-active"><a href="/zh-cn/docs/overview/what-is-seata.html" target="_self">文档</a></li><li class="menu-item menu-item-normal"><a href="/zh-cn/docs/developers/developers_dev.html" target="_self">开发者</a></li><li class="menu-item menu-item-normal"><a href="/zh-cn/blog/index.html" target="_self">博客</a></li><li class="menu-item menu-item-normal"><a href="/zh-cn/community/index.html" target="_self">社区</a></li><li class="menu-item menu-item-normal"><a href="/zh-cn/blog/download.html" target="_self">下载</a></li></ul></div></div></header><div class="bar"><div class="bar-body"><img src="https://img.alicdn.com/tfs/TB1cm8nJwDqK1RjSZSyXXaxEVXa-160-160.png" class="front-img"/><span>文档</span><img src="https://img.alicdn.com/tfs/TB1cm8nJwDqK1RjSZSyXXaxEVXa-160-160.png" class="back-img"/></div></div><section class="content-section"><div class="sidemenu"><div class="sidemenu-toggle"><img src="https://img.alicdn.com/tfs/TB1E6apXHGYBuNjy0FoXXciBFXa-200-200.png"/></div><ul><li class="menu-item menu-item-level-1"><span>概述</span><ul><li style="height:36px;overflow:hidden" class="menu-item menu-item-level-2"><a href="/zh-cn/docs/overview/what-is-seata.html" target="_self">Seata 是什么？</a></li><li style="height:36px;overflow:hidden" class="menu-item menu-item-level-2"><a href="/zh-cn/docs/overview/terminology.html" target="_self">术语表</a></li><li style="height:36px;overflow:hidden" class="menu-item menu-item-level-2"><a href="/zh-cn/docs/overview/faq.html" target="_self">FAQ</a></li></ul></li><li class="menu-item menu-item-level-1"><span>用户文档</span><ul><li style="height:36px;overflow:hidden" class="menu-item menu-item-level-2"><a href="/zh-cn/docs/user/quickstart.html" target="_self">快速启动</a></li><li style="height:36px;overflow:hidden" class="menu-item menu-item-level-2"><a href="/zh-cn/docs/user/saga.html" target="_self">Saga 模式</a></li><li style="height:36px;overflow:hidden" class="menu-item menu-item-level-2"><a href="/zh-cn/docs/user/configurations.html" target="_self">参数配置</a></li><li style="height:36px;overflow:hidden" class="menu-item menu-item-level-2"><a href="/zh-cn/docs/user/transaction-group.html" target="_self">事务分组介绍</a></li><li style="height:36px;overflow:hidden" class="menu-item menu-item-level-2"><a href="/zh-cn/docs/user/spring.html" target="_self">Spring 支持</a></li><li style="height:36px;overflow:hidden" class="menu-item menu-item-level-2"><a href="/zh-cn/docs/user/api.html" target="_self">API 支持</a></li><li style="height:36px;overflow:hidden" class="menu-item menu-item-level-2"><a href="/zh-cn/docs/user/microservice.html" target="_self">微服务框架支持</a></li><li style="height:36px;overflow:hidden" class="menu-item menu-item-level-2"><a href="/zh-cn/docs/user/ormframework.html" target="_self">ORM 框架支持</a></li><li style="height:36px;overflow:hidden" class="menu-item menu-item-level-2"><a href="/zh-cn/docs/user/datasource.html" target="_self">数据源类型支持</a></li></ul></li><li class="menu-item menu-item-level-1"><span>开发者指南</span><ul><li style="height:36px;overflow:hidden" class="menu-item menu-item-level-2"><span>各事务模式<img style="transform:rotate(-90deg)" class="menu-toggle" src="/img/system/arrow_down.png"/></span><ul><li class="menu-item menu-item-level-3"><a href="/zh-cn/docs/dev/mode/at-mode.html" target="_self">Seata AT 模式</a></li><li class="menu-item menu-item-level-3"><a href="/zh-cn/docs/dev/mode/tcc-mode.html" target="_self">Seata TCC 模式</a></li><li class="menu-item menu-item-level-3"><a href="/zh-cn/docs/dev/mode/saga-mode.html" target="_self">Seata Saga 模式</a></li></ul></li><li style="height:36px;overflow:hidden" class="menu-item menu-item-level-2"><a href="/zh-cn/docs/dev/seata-mertics.html" target="_self">Metrics设计</a></li></ul></li><li class="menu-item menu-item-level-1"><span>运维指南</span><ul><li style="height:36px;overflow:hidden" class="menu-item menu-item-level-2"><a href="/zh-cn/docs/ops/operation.html" target="_self">Metrics配置</a></li><li style="height:36px;overflow:hidden" class="menu-item menu-item-level-2"><span>部署<img style="transform:rotate(-90deg)" class="menu-toggle" src="/img/system/arrow_down.png"/></span><ul><li class="menu-item menu-item-level-3"><a href="/zh-cn/docs/ops/deploy-guide-beginner.html" target="_self">新人文档</a></li><li class="menu-item menu-item-level-3"><a href="/zh-cn/docs/ops/deploy-server.html" target="_self">直接部署</a></li><li class="menu-item menu-item-level-3"><a href="/zh-cn/docs/ops/deploy-by-docker.html" target="_self">Docker部署</a></li><li class="menu-item menu-item-level-3"><a href="/zh-cn/docs/ops/deploy-by-kubernetes.html" target="_self">Kubernetes部署</a></li><li class="menu-item menu-item-level-3"><a href="/zh-cn/docs/ops/deploy-by-helm.html" target="_self">Helm 部署</a></li></ul></li></ul></li></ul></div><div class="doc-content markdown-body"><h1>部署指南</h1>
<h2>Seata新手部署指南(1.0.0版本)</h2>
<p>Seata分TC、TM和RM三个角色，TC（Server端）为单独服务端部署，TM和RM（Client端）由业务系统集成。</p>
<h3>资源目录介绍</h3>
<h4><a href="https://github.com/seata/seata/tree/develop/script" target="_blank">script</a></h4>
<ul>
<li>client</li>
</ul>
<blockquote>
<p>存放client端sql脚本，参数配置</p>
</blockquote>
<ul>
<li>config-center</li>
</ul>
<blockquote>
<p>各个配置中心参数导入脚本，config.txt(包含server和client，原名nacos-config.txt)为通用参数文件</p>
</blockquote>
<ul>
<li>server</li>
</ul>
<blockquote>
<p>server端数据库脚本及各个容器配置</p>
</blockquote>
<h3>注意事项</h3>
<ul>
<li>seata-spring-boot-starter</li>
</ul>
<blockquote>
<p>1.0.0可用于替换seata-all，GlobalTransactionScanner自动初始化（依赖SpringUtils）<br>
若其他途径实现GlobalTransactionScanner初始化，请保证io.seata.spring.boot.autoconfigure.util.SpringUtils先初始化；<br>
starter默认开启数据源自动代理，用户若再手动配置DataSourceProxy将会导致异常</p>
</blockquote>
<ul>
<li>spring-cloud-alibaba-seata</li>
</ul>
<blockquote>
<p>2.1.0内嵌seata-all 0.7.1，2.1.1内嵌seata-all 0.9.0。<br>
截止20191222日，现有版本不能与seata-spring-boot-starter兼容，后续sca会提供新的seata集成版本；</p>
</blockquote>
<pre><code>    临时兼容解决方案(单选即可): 
    a.@SpringBootApplication注解内exclude掉spring-cloud-alibaba-seata内的com.alibaba.cloud.seata.GlobalTransactionAutoConfiguration
    b.让SpringUtils先初始化
</code></pre>
<h3>启动Server</h3>
<p>Server端存储模式（store.mode）现有file、db两种（后续将引入raft），file模式无需改动，直接启动即可，下面专门讲下db启动步骤。<br>
注：file模式为单机模式，全局事务会话信息内存中读写并持久化本地文件root.data，性能较高;<br>
db模式为高可用模式，全局事务会话信息通过db共享，相应性能差些。</p>
<h4>步骤一：启动包</h4>
<ul>
<li><a href="https://github.com/seata/seata/releases" target="_blank">点击下载</a></li>
<li>官方钉钉群（群号：23171167，1群5000人已满，<a href="http://seata.io/zh-cn/community/index.html" target="_blank">2群</a>），qq群（群号：254657148）群文件共享下载</li>
<li>其它途径</li>
</ul>
<h4>步骤二：建表</h4>
<p>全局事务会话信息由3块内容构成，全局事务--&gt;分支事务--&gt;全局锁，对应表global_table、branch_table、lock_table</p>
<h4>步骤三：修改store.mode</h4>
<p>启动包: seata--&gt;conf--&gt;file.conf，修改store.mode=&quot;db&quot;<br>
源码:   根目录--&gt;seata-server--&gt;resources--&gt;file.conf，修改store.mode=&quot;db&quot;</p>
<h4>步骤四：修改数据库连接</h4>
<p>启动包: seata--&gt;conf--&gt;file.conf，修改store.db相关属性。<br>
源码:   根目录--&gt;seata-server--&gt;resources--&gt;file.conf，修改store.db相关属性。</p>
<h4>步骤五：启动</h4>
<ul>
<li>源码启动: 执行Server.java的main方法</li>
<li>命令启动: <a href="http://seata-server.sh">seata-server.sh</a> -h 127.0.0.1 -p 8091 -m db -n 1 -e test</li>
</ul>
<pre><code>    -h: 注册到注册中心的ip
    -p: Server rpc 监听端口
    -m: 全局事务会话信息存储模式，file、db，优先读取启动参数
    -n: Server node，多个Server时，需区分各自节点，用于生成不同区间的transactionId，以免冲突
    -e: 多环境配置参考 http://seata.io/en-us/docs/ops/multi-configuration-isolation.html
</code></pre>
<ul>
<li><a href="https://seata.io/zh-cn/docs/ops/deploy-by-docker.html" target="_blank">点击查看docker部署</a></li>
</ul>
<p>注: 堆内存建议分配2G，堆外内存1G</p>
<h3>业务系统集成Client</h3>
<h4>步骤一：添加seata依赖（建议单选）</h4>
<ul>
<li>依赖seata-all</li>
<li>依赖seata-spring-boot-starter，支持yml配置</li>
<li>依赖spring-cloud-alibaba-seata，内部集成了seata，并实现了xid传递</li>
</ul>
<h4>步骤二：undo_log建表、配置参数</h4>
<ul>
<li><a href="https://seata.io/zh-cn/docs/user/configurations.html" target="_blank">点击查看参数配置介绍</a></li>
</ul>
<h4>步骤三：数据源代理</h4>
<ul>
<li>0.9.0版本开始seata支持自动代理数据源</li>
</ul>
<pre><code>    1.0.0: client.support.spring.datasource.autoproxy=true  
    0.9.0: support.spring.datasource.autoproxy=true
</code></pre>
<ul>
<li>手动配置可参考下方的例子</li>
</ul>
<pre><code> @Bean
    @ConfigurationProperties(prefix = &quot;spring.datasource&quot;)
    public DataSource druidDataSource() {
        DruidDataSource druidDataSource = new DruidDataSource();
        return druidDataSource;
    }
    @Primary
    @Bean(&quot;dataSource&quot;)
    public DataSourceProxy dataSource(DataSource druidDataSource) {
        return new DataSourceProxy(druidDataSource);
    }
</code></pre>
<h4>步骤四：初始化GlobalTransactionScanner</h4>
<ul>
<li>手动</li>
</ul>
<pre><code class="language-@Bean">       public GlobalTransactionScanner globalTransactionScanner() {
           String applicationName = this.applicationContext.getEnvironment().getProperty(&quot;spring.application.name&quot;);
           String txServiceGroup = this.seataProperties.getTxServiceGroup();
           if (StringUtils.isEmpty(txServiceGroup)) {
               txServiceGroup = applicationName + &quot;-fescar-service-group&quot;;
               this.seataProperties.setTxServiceGroup(txServiceGroup);
           }
   
           return new GlobalTransactionScanner(applicationName, txServiceGroup);
       }
</code></pre>
<ul>
<li>自动，引入seata-spring-boot-starter、spring-cloud-alibaba-seata等jar</li>
</ul>
<h4>步骤五：实现xid跨服务传递</h4>
<ul>
<li>手动
参考源码integration文件夹下的各种rpc实现 module</li>
<li>自动
springCloud用户可以引入spring-cloud-alibaba-seata，内部已经实现xid传递</li>
</ul>
<p><a href="https://seata.io/zh-cn/docs/user/transaction-group.html">查看事务分组介绍</a></p>
</div></section><footer class="footer-container"><div class="footer-body"><img src="/img/seata_logo_gray.png"/><p class="docsite-power">website powered by docsite</p><div class="cols-container"><div class="col col-12"><h3>愿景</h3><p>Seata 是一款阿里巴巴开源的分布式事务解决方案，致力于在微服务架构下提供高性能和简单易用的分布式事务服务。</p></div><div class="col col-6"><dl><dt>文档</dt><dd><a href="/zh-cn/docs/overview/what-is-seata.html" target="_self">Seata 是什么？</a></dd><dd><a href="/zh-cn/docs/user/quickstart.html" target="_self">快速开始</a></dd><dd><a href="https://github.com/seata/seata.github.io/issues/new" target="_self">报告文档问题</a></dd><dd><a href="https://github.com/seata/seata.github.io" target="_self">在Github上编辑此文档</a></dd></dl></div><div class="col col-6"><dl><dt>资源</dt><dd><a href="/zh-cn/blog/index.html" target="_self">博客</a></dd><dd><a href="/zh-cn/community/index.html" target="_self">社区</a></dd></dl></div></div><div class="copyright"><span>Copyright © 2019 Seata</span></div></div></footer></div></div>
	<script src="https://f.alicdn.com/react/15.4.1/react-with-addons.min.js"></script>
	<script src="https://f.alicdn.com/react/15.4.1/react-dom.min.js"></script>
	<script>
		window.rootPath = '';
  </script>
	<script src="/build/documentation.js"></script>
	<script>
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?104e73ef0c18b416b27abb23757ed8ee";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
    </script>
</body>
</html>
